﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataTransferObject
{
    /*
     * Lưu các thông tin cấu hình trong OptionForm
     * Dự kiến thông tin lưu trong file sẽ dưới dạng XML để dễ có một chuẩn thao tác, và trao đổi rõ ràng, chuyên nghiệp
     */
    #region Các cấu trúc hỗ trợ lưu trữ
    /// <summary>
    /// dùng để chứa một khối timeblock trong system config
    /// sử dụng chủ yếu cho tab Working Hour
    /// </summary>
    public class FromTimeToTime 
    {
        /// <summary>
        /// thời điểm bắt đầu của khối timeblock
        /// </summary>
        private DateTime startTime;
        /// <summary>
        /// thời điểm kết thúc của khối time block
        /// </summary>
        private DateTime toTime;

        public DateTime StartTime
        {
            get { return this.startTime; }
            set { this.startTime = value; }
        }

        public DateTime ToTime
        {
            get { return this.toTime; }
            set { this.toTime = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FromTimeToTime"/> struct.
        /// </summary>
        /// <param name="fromT">From T.</param>
        /// <param name="toT">To T.</param>
        public FromTimeToTime(DateTime fromT, DateTime toT)
        {
            startTime = fromT;
            toTime = toT;
        }


    }

    /// <summary>
    /// lưu trữ dữ liệu của tab Task trong option form
    /// </summary>
    [Serializable]
    public class TabTask
    {
        #region Description

        //
        //  @ Project : JSKE
        //  @ File Name : SystemConfiguration.cs
        //  @ Date : 3/12/2010
        //  @ Author : Luan.Mai
        //
        //

        #endregion

        #region Attributes
        //***********************************
        //tab Tasks

        private DateTime startScheduleDate;
        private Boolean defaultToCurrentDateTime;

        //region: schedule task in the following folder
        private int orderBy;
        private int orderByType;
        private int andThenBy;
        private int andThenByType;
        private int andThenThenBy;
        private int andThenThenByType;
        //region: Folders
        private String scheduleTheTaskIn;
        private String moveCompletedTaskTo;
        private Boolean checkboxMoveCompletedTaskTo;
        private Boolean deleteCompletedOccourancesOfReccuringTasks;

        #endregion

        #region Properties

        public DateTime StartScheduleDate
        {
            get { return this.startScheduleDate; }
            set { this.startScheduleDate = value; }
        }

        public Boolean DefaultToCurrentDateTime
        {
            get { return this.defaultToCurrentDateTime; }
            set { this.defaultToCurrentDateTime = value; }
        }

        public int OrderBy
        {
            get { return this.orderBy; }
            set { this.orderBy = value; }
        }

        public int OrderByType
        {
            get { return this.orderByType; }
            set { this.orderByType = value; }
        }

        public int AndThenBy
        {
            get { return this.andThenBy; }
            set { this.andThenBy = value; }
        }

        public int AndThenByType
        {
            get { return this.andThenByType; }
            set { this.andThenByType = value; }
        }

        public int AndThenThenBy
        {
            get { return this.andThenThenBy; }
            set { this.andThenThenBy = value; }
        }

        public int AndThenThenByType
        {
            get { return this.andThenThenByType; }
            set { this.andThenThenByType = value; }
        }

        public String ScheduleTheTaskIn
        {
            get { return this.scheduleTheTaskIn; }
            set { this.scheduleTheTaskIn = value; }
        }

        public String MoveCompletedTaskTo
        {
            get { return this.moveCompletedTaskTo; }
            set { this.moveCompletedTaskTo = value; }
        }

        public Boolean CheckboxMoveCompletedTaskTo
        {
            get { return this.checkboxMoveCompletedTaskTo; }
            set { this.checkboxMoveCompletedTaskTo = value; }
        }

        public Boolean DeleteCompletedOccourancesOfReccuringTasks
        {
            get { return this.deleteCompletedOccourancesOfReccuringTasks; }
            set { this.deleteCompletedOccourancesOfReccuringTasks = value; }
        }

        #endregion

        #region Constructor

        

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class TabProjects
    {
        #region Attributes

        //***********************************
        //tab Project

        /// <summary>
        /// Danh sách những project. 
        /// Thứ tự hiển thị trong OptionForm từ trên xuống dưới cũng tuân theo thứ tự này
        /// projectName[0] = project có độ ưu tiên cao nhất
        /// projectName[1] = project có độ ưu tiên cao thứ 2
        /// </summary>
        private List<String> projectName;


        #endregion

        #region Properties

        public List<String> ListProjectName
        {
            get { return this.projectName; }
            set { this.projectName = value; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Tabs the projects.
        /// </summary>
        public void tabProjects()
        {
            ListProjectName = new List<String>();
        }

        #endregion

        #region Methods

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class TabCalendar
    {
        #region Description

        #endregion

        #region Attributes

        //***********************************
        //tab Calendar

        //region: create task entry in the calendar

        private Boolean createForTaskThatAreNotStartedOrInProgress;
        private Boolean keepARecordOfCompletedWork;
        private Boolean createAllDayEventForMileStone;
        //region: option for task entry in the calendar

        private Boolean markAllAsPrivate;

        private List<String> showAsCollectionInOptionForTaskEntryInCalendar;
        private int showAsSelectedItem;
        private int showTimeAsSelectedItem;

        //region: Default time allowces before and after an appointment

        private String beforeDefaultAllowces;
        private String afterDefaultAllowces;
        //region: Folders
        private String _myAppointmenFolderPath = string.Empty;
        private String _writeTaskEntriesToPath = string.Empty;

        #endregion

        #region Properties

        public Boolean CreateForTaskThatAreNotStartedOrInProgress
        {
            get { return this.createForTaskThatAreNotStartedOrInProgress; }
            set { this.createForTaskThatAreNotStartedOrInProgress = value; }
        }

        public Boolean KeepARecordOfCompletedWork
        {
            get { return this.keepARecordOfCompletedWork; }
            set { this.keepARecordOfCompletedWork = value; }
        }

        public Boolean CreateAllDayEventForMileStone
        {
            get { return this.createAllDayEventForMileStone; }
            set { this.createAllDayEventForMileStone = value; }
        }

        public Boolean MarkAllAsPrivate
        {
            get { return this.markAllAsPrivate; }
            set { this.markAllAsPrivate = value; }
        }

        public List<String> ShowAsCollectionInOptionForTaskEntryInCalendar
        {
            get { return this.showAsCollectionInOptionForTaskEntryInCalendar; }
            set { this.showAsCollectionInOptionForTaskEntryInCalendar = value; }
        }

        public int ShowAsSelectedItem
        {
            get { return this.showAsSelectedItem; }
            set { this.showAsSelectedItem = value; }
        }

        public int ShowTimeAsSelectedItem
        {
            get { return this.showTimeAsSelectedItem; }
            set { this.showTimeAsSelectedItem = value; }
        }

        public String BeforeDefaultAllowces
        {
            get { return this.beforeDefaultAllowces; }
            set { this.beforeDefaultAllowces = value; }
        }

        public String AfterDefaultAllowces
        {
            get { return this.afterDefaultAllowces; }
            set { this.afterDefaultAllowces = value; }
        }

        public String MyAppointmenFolderPath
        {
            get { return this._myAppointmenFolderPath; }
            set { this._myAppointmenFolderPath = value; }
        }

        public String WriteTaskEntriesToPath
        {
            get { return this._writeTaskEntriesToPath; }
            set { this._writeTaskEntriesToPath = value; }
        }


        #endregion

        #region Constructors

        /// <summary>
        /// Tabs the calendar.
        /// </summary>
        public void tabCalendar()
        {
            showAsCollectionInOptionForTaskEntryInCalendar = new List<String>();
        }

        #endregion

        #region Methods

        #endregion
    }

    /// <summary>
    /// WorkingHourItem sẽ chứa 1 list các MappedFreeTimeList trong một tuần, muốn lấy thêm MappedFreeTimeList cho tuần
    /// sau thì phải dùng các hàm trong MappingService
    /// </summary>
    [Serializable]
    public class WorkingHourItem
    {
        #region Attributes

        private int _workingHourID;
        private String _workingHourName;
        private Boolean[] _multipleDayEdit;
        private Boolean[] _dayChecked;

        private MappedFreeTimeList _workTime;
        

        private Boolean scheduleTaskWhichHaveBeenAssignedInTheseHours;

        public Boolean ScheduleTaskWhichHaveBeenAssignedInTheseHours
        {
            get { return this.scheduleTaskWhichHaveBeenAssignedInTheseHours; }
            set { this.scheduleTaskWhichHaveBeenAssignedInTheseHours = value; }
        }
        #endregion

        #region Properties

        public int WorkingHourID
        {
            get { return this._workingHourID; }
            set { this._workingHourID = value; }
        }
        public String WorkingHourName
        {
            get { return this._workingHourName; }
            set { this._workingHourName = value; }
        }

        public Boolean[] DayChecked
        {
            get { return this._dayChecked; }
            set { this._dayChecked = value; }
        }

        public Boolean[] MultipleDayEdit
        {
            get { return this._multipleDayEdit; }
            set { this._multipleDayEdit = value; }
        }

        public MappedFreeTimeList WorkTime
        {
            get { return this._workTime; }
            set { this._workTime = value; }
        }



        #endregion

        #region Constructors

        public WorkingHourItem(WorkingHourItem copy, string name, int id)
        {
            WorkingHourID = id;
            _workTime = new MappedFreeTimeList();
            _dayChecked = new Boolean[7];
            _multipleDayEdit = new Boolean[7];

            this.WorkingHourName = name;
            this.ScheduleTaskWhichHaveBeenAssignedInTheseHours = copy.ScheduleTaskWhichHaveBeenAssignedInTheseHours;
            this.DayChecked = (bool[])copy.DayChecked.Clone();
            this.MultipleDayEdit = (bool[])copy.MultipleDayEdit.Clone();
            foreach (MappedFreeTimeBlock ftb in copy.WorkTime.ListFreeTimeBlock)
            {
                this._workTime.ListFreeTimeBlock.Add(new MappedFreeTimeBlock(ftb));
            }
        }

        public WorkingHourItem(string name, int id)
        {
            WorkingHourID = id;
            _workTime = new MappedFreeTimeList();
            _dayChecked = new Boolean[7];
            _multipleDayEdit = new Boolean[7];
            this.WorkingHourName = name;
        }
        #endregion

        #region Methods

        public override string ToString()
        {
            return this.WorkingHourName;
        }
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        #endregion

    }




    [Serializable]
    public class TabWorkingHours
    {
        #region Description

        #endregion

        #region Attributes

        //***********************************

        /// <summary>
        /// danh sách những working hour với working time & break
        /// </summary>
        private List<WorkingHourItem> listOfWorkingHourItems;

        private int currentSelectedWorkingHourID;
        
        private int defaultWorkingHourID;
        

        #endregion

        #region Properties

        public List<WorkingHourItem> ListOfWorkingHourItems
        {
            get { return this.listOfWorkingHourItems; }
        }

        public int CurrentSelectedWorkingHourID
        {
            get { return this.currentSelectedWorkingHourID; }
            set { this.currentSelectedWorkingHourID = value; }
        }



        public int DefaultWorkingHourID
        {
            get { return this.defaultWorkingHourID; }
            set { this.defaultWorkingHourID = value; }
        }



        

        #endregion

        #region Constructors

       

        #endregion

        #region Methods


        public void AddWorkingHourItem(WorkingHourItem workingHourItem)
        {
            workingHourItem.WorkingHourID = this.listOfWorkingHourItems.Last().WorkingHourID + 1;
            this.listOfWorkingHourItems.Add(workingHourItem);
        }

        /// <summary>
        /// Tabs the working hours.
        /// </summary>
        public void tabWorkingHours()
        {
            listOfWorkingHourItems = new List<WorkingHourItem>();
        }
        /// <summary>
        /// Removes the working hour item by ID.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Boolean removeWorkingHourItemByID(int id)
        {
            int count = listOfWorkingHourItems.Count - 1;
            listOfWorkingHourItems.RemoveAt(id);
            if (listOfWorkingHourItems.Count == count)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class TabOption
    {
        #region Description

        #endregion

        #region Attributes

        //***********************************
        //tab Option

        //region: Task Start and Due dates
        private Boolean taskShoudSetStartAndDueToTheScheduleDates;
        private List<String> restoreMyOriginalStartAndDate;
        private int selectedRestoreMyOrig;

        //region: Miscellaneous
        private String ifTaskConstraintIsMissedPrefixTaskSubject;
        private String defaultMinimumTaskSplit;
        private Boolean showSumamaryWhenTaskRescheduleIsComplete;

        #endregion

        #region Properties

        public Boolean TaskShoudSetStartAndDueToTheScheduleDates
        {
            get { return this.taskShoudSetStartAndDueToTheScheduleDates; }
            set { this.taskShoudSetStartAndDueToTheScheduleDates = value; }
        }

        public List<String> RestoreMyOriginalStartAndDate
        {
            get { return this.restoreMyOriginalStartAndDate; }
            set { this.restoreMyOriginalStartAndDate = value; }
        }

        public int SelectedRestoreMyOrig
        {
            get { return this.selectedRestoreMyOrig; }
            set { this.selectedRestoreMyOrig = value; }
        }

        public String IfTaskConstraintIsMissedPrefixTaskSubject
        {
            get { return this.ifTaskConstraintIsMissedPrefixTaskSubject; }
            set { this.ifTaskConstraintIsMissedPrefixTaskSubject = value; }
        }

        public String DefaultMinimumTaskSplit
        {
            get { return this.defaultMinimumTaskSplit; }
            set { this.defaultMinimumTaskSplit = value; }
        }

        public Boolean ShowSumamaryWhenTaskRescheduleIsComplete
        {
            get { return this.showSumamaryWhenTaskRescheduleIsComplete; }
            set { this.showSumamaryWhenTaskRescheduleIsComplete = value; }
        }

        #endregion

        #region Constructors

        public void tabOption()
        {
            restoreMyOriginalStartAndDate = new List<String>();
        }

        #endregion

        #region Methods

        #endregion

    }

    #endregion

    /// <summary>
    /// Lưu thông tin cấu hình của hệ thống
    /// Việc lưu trữ được nhờ vào nhiều cấu trúc lưu trữ ở phía trên
    /// </summary>
    [Serializable]
    public class SystemConfiguration
    {
        #region Description

        #endregion

        #region Attributes

        // neu la 0: simple mode, 1: advance mode
        private int isSimpleModeOrAdvanceMode;

        public TabTask TabTaskData;
        public TabProjects TabProjectData;
        public TabCalendar TabCalendarData;
        public TabWorkingHours TabWorkingHoursData;
        public TabOption TabOptionData;


        // SingleTon pattern
        private static SystemConfiguration systemConfiguration = null;
        #endregion

        #region Essential Methods


        #endregion

        #region Properties

        public int IsSimpleModeOrAdvanceMode
        {
            get { return this.isSimpleModeOrAdvanceMode; }
            set { this.isSimpleModeOrAdvanceMode = value; }
        }


        #endregion

        #region bổ sung
        /* @LUÂN
         * CÁC BẠN CÓ THỂ:
         * 1. COMMENT VỀ NHỮNG BỔ SUNG GÓP Ý
         * 2. VIẾT CODE ĐỀ XUẤT TRONG REGION NÀY
         * 
        */
        /// <summary>
        /// Initializes a new instance of the <see cref="SystemConfiguration"/> class.
        /// </summary>
        private SystemConfiguration()
        {
            TabTaskData = new TabTask();
            
            TabProjectData = new TabProjects();
            TabProjectData.tabProjects();

            TabWorkingHoursData = new TabWorkingHours();
            TabWorkingHoursData.tabWorkingHours();

            TabCalendarData = new TabCalendar();
            TabCalendarData.tabCalendar();

            TabOptionData = new TabOption();
            TabOptionData.tabOption();
        }
        /*
         * sử dụng hàm getInstance để trong quá trình application chạy, chỉ tồn tại 1 object SystemConfiguration
         * có thể thêm vào paramter để tạo systemConfiguration theo 1 file Config.xml
        */
        /// <summary>
        /// Gets the instance of the systemconfig, implemented by Singleton Pattern
        /// </summary>
        /// <returns></returns>
        public static SystemConfiguration getInstance()
        {
            if (systemConfiguration == null)
            {
                return new SystemConfiguration();
            }
            else
            {
                return systemConfiguration;
            }
        }

        public DateTime GetStartSchedule()
        {
            return TabTaskData.StartScheduleDate;
        }
        #endregion

    }
}
